var cc__decorate = __decorate;
Object.defineProperty(exports, "__esModule", {
  value: true
});
var $2NativeAdMgr = require("NativeAdMgr");
var $2PlatformMgr = require("PlatformMgr");
var $2ObjUtil = require("ObjUtil");
var cc__decorator = cc._decorator;
var ccp_ccclass = cc__decorator.ccclass;
var ccp_property = cc__decorator.property;
var def_ComNativeView = /* */function (_cc$Component7) {
  function _ctor() {
    var _this13;
    babel_classCallCheck(this, _ctor);
    _this13 = _callSuper(this, _ctor, arguments);
    _this13.quit = null;
    _this13.logoUrl = null;
    _this13.sign = null;
    _this13.text = null;
    _this13.click_text = null;
    _this13.bg = null;
    _this13.refresh = 3e4;
    _this13.other = null;
    _this13.nativeId = 0;
    _this13.adname = "";
    _this13.lastid = "";
    _this13.newNative = false;
    _this13.adres = [];
    return _this13;
  }
  babel_inherits(_ctor, _cc$Component7);
  return babel_createClass(_ctor, [{
    key: "onLoad",
    value: function onLoad() {
      this.node.on(cc.Node.EventType.TOUCH_START, this.clickAd, this);
      this.quit.active = false;
      console.log("当前的内容节点的显隐情况：", this.node.active, this.node.opacity);
      if (!(0 != this.node.active && 0 != this.node.opacity)) {
        this.bg.active = false;
        this.other.active = false;
      }
      null != this.bg && (this.bg.active = false);
      null != this.text && (this.text.string = "");
      if (null != this.click_text) {
        "gobutton" == this.click_text.node.parent.name && (this.click_text.node.parent.active = false);
        this.click_text.string = "";
      }
    }
  }, {
    key: "onEnable",
    value: function onEnable() {
      this.other && (this.other.active = false);
      $2PlatformMgr.default.Instance().showNativeAD(this.nativeId, this.node);
      if (this.newNative) {
        $2PlatformMgr.default.Instance().reportAdShow(this.nativeId);
        this.newNative = false;
      }
    }
  }, {
    key: "onDisable",
    value: function onDisable() {
      this.other && (this.other.active = false);
    }
  }, {
    key: "addPermanent",
    value: function addPermanent(e) {
      this.adres.push(e);
    }
  }, {
    key: "init",
    value: function init(e) {
      var _this14 = this;
      console.log("收到更新数据：", this.adname, this.nativeId, e);
      if (null == e) {
        return void (this.node.active = false);
      }
      this.refresh > 0 && setTimeout(function () {
        if (cc.isValid(_this14.node, true)) {
          console.log("showNativeAD", _this14.nativeId);
          $2PlatformMgr.default.Instance().showNativeAD(_this14.nativeId, _this14.node);
        }
      }, this.refresh);
      if (this.node.activeInHierarchy) {
        $2PlatformMgr.default.Instance().reportAdShow(this.nativeId);
      } else {
        this.newNative = true;
      }
      if (!e) {
        return;
      }
      if (this.lastid == e.adId) {
        return void console.log("广告没有刷新");
      }
      "gobutton" == this.click_text.node.parent.name && (this.click_text.node.parent.active = true);
      this.text.string = e.desc;
      this.click_text.string = e.clickBtnTxt;
      var t = this;
      var n = $2ObjUtil.default.isString(e.imgUrlList) ? e.imgUrlList : e.imgUrlList[0];
      console.log("url: " + n);
      if (this.adres.length > 0) {
        var _iterator = babel_createForOfIteratorHelper(this.adres);
        var _step;
        try {
          for (_iterator.s(); !(_step = _iterator.n()).done;) {
            var _e8 = _step.value;
            _e8 != n && cc.loader.release(_e8);
          }
        } catch (err) {
          _iterator.e(err);
        } finally {
          _iterator.f();
        }
        this.adres = [];
      }
      switch (e.creativeType) {
        case 1:
          cc.loader.load(n, function (e, o) {
            console.log("加载imbgUrlList", n);
            if (e) {
              console.error(e);
            } else {
              _this14.addPermanent(n);
              var _e9 = new cc.SpriteFrame(o);
              t.logoUrl.spriteFrame = _e9;
              t.quit.active = true;
              t.bg.active = true;
            }
          });
          break;
        case 2:
          break;
        case 3:
          cc.loader.load(e.icon, function (e, o) {
            console.log("加载, 加载广告图imbgUrlList", n);
            if (e) {
              console.error(e);
            } else {
              _this14.addPermanent(n);
              var _e10 = new cc.SpriteFrame(o);
              t.logoUrl.spriteFrame = _e10;
              t.quit.active = true;
              _this14.bg.active = true;
            }
          });
          break;
        case 4:
        case 6:
          break;
        case 7:
          cc.loader.load(n, function (e, o) {
            console.log("加载imbgUrlList");
            if (e) {
              console.error(e);
            } else {
              _this14.addPermanent(n);
              var _e11 = new cc.SpriteFrame(o);
              t.logoUrl.spriteFrame = _e11;
              t.quit.active = true;
              t.bg.active = true;
            }
          });
          break;
        case 8:
          cc.loader.load(n, function (e, o) {
            console.log("加载imbgUrlList", e);
            if (e) {
              console.error(e);
            } else {
              _this14.addPermanent(n);
              var _e12 = new cc.SpriteFrame(o);
              t.logoUrl.spriteFrame = _e12;
              t.quit.active = true;
              t.bg.active = true;
            }
          });
          break;
        default:
          cc.loader.load(n, function (e, o) {
            console.log("加载imbgUrlList", n);
            if (e) {
              console.error(e);
            } else {
              _this14.addPermanent(n);
              var _e13 = new cc.SpriteFrame(o);
              console.log("--------------------这个图片如何了：", _e13);
              t.logoUrl.spriteFrame = _e13;
              t.quit.active = true;
              t.bg.active = true;
            }
          });
      }
      if (null != e.logoUrl) {
        console.log("加载logoUrl");
        cc.loader.load(e.logoUrl, function (e, o) {
          if (e) {
            console.error(e);
          } else {
            _this14.addPermanent(n);
            var _e14 = new cc.SpriteFrame(o);
            t.sign.spriteFrame = _e14;
            _this14.other.active = true;
          }
        });
      }
    }
  }, {
    key: "clickAd",
    value: function clickAd() {
      if (0 != this.node.opacity) {
        console.log("用户点击了原生广告");
        $2PlatformMgr.default.Instance().clickNativeAD(this.nativeId);
        $2PlatformMgr.default.Instance().showNativeAD(this.nativeId, this.node);
      }
    }
  }, {
    key: "quitAd",
    value: function quitAd() {
      console.log("用户关闭原生广告");
      this.node.active = false;
      $2NativeAdMgr.default.Instance.Destroy();
    }
  }]);
}(cc.Component);
cc__decorate([ccp_property(cc.Node)], def_ComNativeView.prototype, "quit", undefined);
cc__decorate([ccp_property(cc.Sprite)], def_ComNativeView.prototype, "logoUrl", undefined);
cc__decorate([ccp_property(cc.Sprite)], def_ComNativeView.prototype, "sign", undefined);
cc__decorate([ccp_property(cc.Label)], def_ComNativeView.prototype, "text", undefined);
cc__decorate([ccp_property(cc.Label)], def_ComNativeView.prototype, "click_text", undefined);
cc__decorate([ccp_property(cc.Node)], def_ComNativeView.prototype, "bg", undefined);
cc__decorate([ccp_property], def_ComNativeView.prototype, "refresh", undefined);
cc__decorate([ccp_property(cc.Node)], def_ComNativeView.prototype, "other", undefined);
cc__decorate([ccp_property()], def_ComNativeView.prototype, "nativeId", undefined);
def_ComNativeView = cc__decorate([ccp_ccclass], def_ComNativeView);
exports.default = def_ComNativeView;